package org.hismig.migration.result;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class ResultInfo extends BaseInfo {

	private int effectCount;

	private String sql;

	public int getEffectCount() {
		return effectCount;
	}

	public void setEffectCount(int effectCount) {
		this.effectCount = effectCount;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public ResultInfo(String name) {
		this.name = name;
	}

	public String formate() {
		StringBuffer sb = new StringBuffer();

		sb.append("<html>");
		sb.append(String.format("<strong>脚本 : </strong>%s<p>", name));
		sb.append(String.format("<strong>耗时 : </strong>%sms<p>",
				getExecuteTime()));
		if (getErrorCount() > 0) {
			sb.append(String.format(
					"<strong><font color='red'>错误 : %s</font></strong><p>",
					getErrorCount()));
		} else {
			sb.append(String.format(
					"<strong><font color='green'>错误 : %s</font></strong><p>",
					getErrorCount()));
		}
		sb.append(String.format("<strong>影响行数 : </strong>%s<p>", effectCount));
		sb.append(String.format("<strong>SQL : </strong><pre>%s</pre>", sql));

		sb.append("</html>");

		return sb.toString();
	}

	@Override
	public String toString() {
		return String.format("%s <耗时:%sms> (错误:%s)", new Object[]{name,
				getExecuteTime(), getErrorCount()});
	}

}
